package com.google.code.jtasks.server.modules;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import com.google.inject.Singleton;
import com.google.inject.BindingAnnotation;
import com.google.inject.servlet.RequestScoped;
import com.mongodb.DB;
import com.mongodb.MongoClient;

import javax.inject.Inject;
import java.net.UnknownHostException;
import java.util.HashMap;
import java.util.Map;

/**
 * A module for MongoDB connection configuration.
 */
public class MongoDBConfigurationModule extends AbstractModule {
    @Override
    protected void configure() {
    }

    @Provides @Singleton
    public MongoClient mongoClient() {
        try {
            return new MongoClient("127.0.0.1");
        } catch (UnknownHostException e) {
            throw new RuntimeException("Impossible happened");
        }
    }
   @Provides
    public DB taskDatabase(MongoClient client) {
        return client.getDB("tasks");
    }

    @Provides
    @BindingDBUsers
    public DB userDatabase(MongoClient client) {
        return client.getDB("users");
    }




}
